// dllmain.cpp : Defines the entry point for the DLL application.
#include "asynframeimpl.h"
#include "stdafx.h"

#if (TARGET_OS == OS_POSIX)

#if (OS_COMPILER == CC_GCC)
void __attribute__((used)) so_section_init(void)
{
    asm(".section .init");
    asm(".section .text");
}
void __attribute__((used)) so_section_fini(void)
{
    asm(".section .fini");
    asm(".section .text");
}
#endif

#elif (TARGET_OS == OS_WIN)

BOOL APIENTRY DllMain(HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReserved)
{
    switch (ul_reason_for_call) {
    case DLL_PROCESS_ATTACH:
    case DLL_THREAD_ATTACH:
    case DLL_THREAD_DETACH:
    case DLL_PROCESS_DETACH:
        break;
    }
    return TRUE;
}

#endif

static_const stdcom_entry_t clsobject[] = {{CLSID_CAsynFrame, &ClassFactory<CAsynFrameImpl>::GetClass, "asynframe.V1"}};

static_const stdcom_entry_t* GetClassObjectMap()
{
    return clsobject;
}
static_const long GetClassObjectMapSize()
{
    return sizeof(clsobject) / sizeof(clsobject[0]);
}
std_com_export DllGetClassObject(REFCLSID clsid, REFIID iid, void** ppv)
{
    size_t i = 0;
    for (i = 0; i < sizeof(clsobject) / sizeof(clsobject[0]); ++i) {
        if (clsid == clsobject[i].clsid) {
            return clsobject[i].pfnGetClassObject(iid, ppv);
        }
    }
    return E_INVALIDARG;
}
_stdmethod_export(CLSID, DllGetAt)(LONG index)
{
    const stdcom_entry_t* array = GetClassObjectMap();
    return array[index].clsid;
}
_stdmethod_export(LONG, DllGetCount)()
{
    const long count = GetClassObjectMapSize();
    return (count > 0) ? count : 0;
}
_stdmethod_export(LPCSTR, DllProgIDFromCLSID)(REFCLSID clsid)
{
    const stdcom_entry_t* array = GetClassObjectMap();
    long i = 0;
    for (i = 0; i < GetClassObjectMapSize(); ++i) {
        if (clsid == array[i].clsid) {
            return array[i].progid;
        }
    }
    return "";
}
std_com_export DllCanUnloadNow(void)
{
    return S_OK;
}
std_com_export DllRegisterServer(void)
{
    return S_OK;
}
std_com_export DllUnregisterServer(void)
{
    return S_OK;
}
std_com_export DllStart(void)
{
    return S_OK;
}
std_com_export DllStop(void)
{
    return S_OK;
}
std_com_export DllSetup(UINT type, UINT version)
{
    return S_OK;
}
_stdmethod_export(LONG, DllGetVersion)()
{
    return 0;
}
